package com.xiaomazi.edu.controller.front;

import com.xiaomazi.common.utils.R;
import com.xiaomazi.edu.entity.Course;
import com.xiaomazi.edu.entity.Teacher;
import com.xiaomazi.edu.service.CourseService;
import com.xiaomazi.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: llxy-parent
 * @description: 前台老师和课程相关数据
 * @author: 小马子
 * @create: 2023-02-23 10:50
 **/
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index() {
        List<Course> courseList = courseService.query().orderByDesc("id").last("LIMIT 8").list();
        List<Teacher> teacherList = teacherService.query().orderByDesc("id").last("LIMIT 4").list();
        return R.ok().data("courseHotList",courseList).data("teacherHotList",teacherList);
    }
}
